package com.study.java.jinjie.GUI;

import javax.swing.*;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Author: MuMu
 * @Date: 2024/4/1 20:42
 */
public class MyGUI {
    public static void main(String[] args) {
        /*
        AWT  Swing  JavaFx
        */

        /*JFrame jFrame = new JFrame("窗体");
        // 设置大小
        jFrame.setSize(500, 350);
        //设置位置
        //jFrame.setLocation(200, 200);
        // 居中位置
        jFrame.setLocationRelativeTo(null);

        // 关闭按钮操作
        jFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


        // 创建文本
        JLabel label = new JLabel("Hello, World!");
        jFrame.add(label);

        // 窗体可见
        jFrame.setVisible(true);*/

        time();
    }


    public static void jPanel(){
        JFrame frame = new JFrame("My Frame");
        JPanel panel = new JPanel();
        JButton button = new JButton("Click Me");
        panel.add(button);
        frame.add(panel);
        frame.setSize(300, 200);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setVisible(true);
    }

    private static void time(){
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");


        JFrame jFrame = new JFrame("shizhong");
        jFrame.setSize(400, 240);
        jFrame.setLocationRelativeTo(null);
        JLabel label = new JLabel( "Time: ");
        jFrame.add(label);
        jFrame.setVisible(true);

        Runnable runnable = new Runnable() {
            @Override
            public void run() {
                while (true){
                    Date date = new Date();
                    String data1 = simpleDateFormat.format(date);
                    label.setText("Time: "+data1);
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };

        Thread thread = new Thread(runnable);
        thread.start();
    }

}
